import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        s.testFunction();
    }

    public List<String> topKFrequent(String[] words, int k) {
        /**
         * 前k个高频单词
         * */
        // 1 统计单词频率
        HashMap<String, Integer> map = new HashMap<>();
        for(String e: words) {
            map.put(e, map.getOrDefault(e, 0) + 1);
        }

        // 2 优先级队列解决top k问题
        // -创建小根堆并传递相反比较规则
        PriorityQueue<Map.Entry<String, Integer>> heap = new PriorityQueue<>((e1, e2) -> {
            int compareValue = e1.getValue() - e2.getValue();
            return compareValue == 0 ? e2.getKey().compareTo(e1.getKey()) : compareValue;
        });
        for(Map.Entry<String, Integer> e: map.entrySet()) {
            heap.offer(e);
            if(heap.size() > k) {
                heap.poll();
            }
        }

        // 3 返回值
        List<String> retList = new ArrayList<>();
        while(!heap.isEmpty()) {
            retList.add(heap.poll().getKey());
        }
        Collections.reverse(retList);
        return retList;
    }

    public void testFunction() {
        /**
         * 测试代码*/
        int[] arr = new int[10];
        arr[0] = 10;
        Arrays.sort(arr);
        for(int e: arr) {
            System.out.print(e + " ");
        }
    }
}
